<?php

require("lib/Util.php");


srand((double) microtime() * 1000000);
$num = rand() % 100;

$str= "1";
for($i=2;$i<=21;$i++){
	$str.=",$i";
}
$str.="\n";

for($i=0;$i<88;$i++){
	$str.= R2(52,36).",";//1
	$str.= R4(5,36,30,17).",";//2
	$str.= R2(33,55).",";//3
	$str.= R4(10,28,32,18).",";//4
	$str.= R4(52,6,0,30).",";//5
	$str.= R4(0,27,56,5).",";//6
	$str.= R4(35,47,3,3).",";//7
	$str.= R5(67,0,11,0,10).",";//8
	$str.= R4(5,62,12,9).",";//9
	$str.= R5(4,20,26,35,3).",";//10
	$str.= R4(8,54,17,9).",";//11
	$str.= R5(0,2,27,23,36).",";//12
	$str.= R5(1,20,15,41,11).",";//12
	$str.= R5(13,26,33,8,8).",";//12
	$str.= R5(16,32,29,9,2).",";//12
	$str.= R5(18,30,28,8,4).",";//12
	$str.= R5(12,28,37,5,6).",";//12
	$str.= R5(4,26,18,10,30).",";//13
	$str.= R6(45,23,9,8,1,2).",";//14
	$str.= R4(46,20,18,4).",";//15
	$str.= R4(51,30,6,1);//16
	
	$str.="\n";
}

//echo $str;
download_str($str,"sample.csv");

function R2($a,$b){
	if(($a+$b)!=88){
		echo "Error:$a,$b";exit;
	}
	srand((double) microtime() * 1000000);
	$rand = rand() % ($a+$b);
	if($rand<$a){
		return 1;
	}else{
		return 2;
	}
}
function R4($a,$b,$c,$d){
	if(($a+$b+$c+$d)!=88){
		echo "Error:$a,$b,$c,$d";exit;
	}
	srand((double) microtime() * 1000000);
	$rand = rand() % ($a+$b+$c+$d);
	if($rand<$a){
		return 1;
	}elseif($rand < $a+$b){
		return 2;
	}elseif($rand < $a+$b+$c){
		return 3;
	}else{
		return 4;
	}
}
function R5($a,$b,$c,$d,$e){
	if(($a+$b+$c+$d+$e)!=88){
		echo "Error:$a,$b,$c,$d";exit;
	}
	srand((double) microtime() * 1000000);
	$rand = rand() % ($a+$b+$c+$d+$e);
	//return $rand;
	if($rand<$a){
		return 1;
	}elseif($rand < $a+$b){
		return 2;
	}elseif($rand < $a+$b+$c){
		return 3;
	}elseif($rand < $a+$b+$c+$d){
		return 4;
	}else{
		return 5;
	}
}

function R6($a,$b,$c,$d,$e,$f){
	if(($a+$b+$c+$d+$e+$f)!=88){
		echo "Error:$a,$b,$c,$d";exit;
	}
	srand((double) microtime() * 1000000);
	$rand = rand() % ($a+$b+$c+$d+$e+$f);
	if($rand<$a){
		return 1;
	}elseif($rand < $a+$b){
		return 2;
	}elseif($rand < $a+$b+$c){
		return 3;
	}elseif($rand < $a+$b+$c+$d){
		return 4;
	}elseif($rand < $a+$b+$c+$d+$e){
		return 5;
	}else{
		return 6;
	}
}


?>